package com.mavenlu.play.base.webview;

import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;

import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;



/**
 * Created by yfjin on 2017/9/6.
 */

public class WrapWebView extends WebView {
    public WrapWebView(Context context) {
        super(context);
        initWebViewSettings(context);
    }

    public WrapWebView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        initWebViewSettings(context);
    }


    private void initWebViewSettings(Context context) {

        WebSettings ws=getSettings();

        ws.setJavaScriptEnabled(true);

        ws.setBlockNetworkImage(false);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
            ws.setMixedContentMode(android.webkit.WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }

//        ws.setUseWideViewPort(true);
//        ws.setSupportZoom(true);
//        ws.setBlockNetworkImage(true);
//        ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
//        ws.setLoadWithOverviewMode(true);
        ws.setAllowFileAccess(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            ws.setAllowFileAccessFromFileURLs(true);
            ws.setAllowUniversalAccessFromFileURLs(true);
        }

        String path=context.getApplicationContext().getCacheDir().getAbsolutePath();
//        path=FileUtil.getCachePath(this);
        ws.setAppCachePath(path);
        ws.setDatabaseEnabled(true);
        ws.setDomStorageEnabled(true);
        ws.setAppCacheMaxSize(1024 * 1024 * 8);
        ws.setAppCacheEnabled(true);
        ws.setCacheMode(WebSettings.LOAD_DEFAULT);


        ws.setGeolocationEnabled(true);
        ws.setJavaScriptCanOpenWindowsAutomatically(true);
        ws.setPluginState(WebSettings.PluginState.ON_DEMAND);







        ws.setJavaScriptEnabled(true);
        ws.setJavaScriptCanOpenWindowsAutomatically(true);
        ws.setCacheMode(WebSettings.LOAD_NO_CACHE);
        ws.setDomStorageEnabled(true);
        ws.setDatabaseEnabled(true);
        ws.setAppCacheEnabled(true);
        ws.setAllowFileAccess(true);
        ws.setSavePassword(true);
        ws.setSupportZoom(true);
        ws.setBuiltInZoomControls(true);
        ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        ws.setUseWideViewPort(true);

        ws.setDisplayZoomControls(false);
    }



}
